package com.joeyzh.iframe.db.utils;

import com.joeyzh.iframe.db.BaseDbEntityDaoUtil;
import com.joeyzh.iframe.db.dao.UserEntityDao;
import com.joeyzh.iframe.db.entity.UserEntity;

import java.util.List;

/**
 * Created by Joey on 2018/10/30.
 *
 * @author Joey
 */

public class DbUserManager extends BaseDbEntityDaoUtil<UserEntity, UserEntityDao> {

    @Override
    public boolean insert(UserEntity entity) {
        return super.insert(entity);
    }

    @Override
    public UserEntity queryById(String id) {
        UserEntity entity = super.queryById(id);
        return entity;
    }

    @Override
    public void update(UserEntity entity) {
        super.update(entity);
    }

    @Override
    public List<UserEntity> getAll() {
        return super.getAll();
    }

    /**
     * 判断是否存在 （添加/删除）
     *
     * @param entity
     */
    public void insertUser(UserEntity entity) {
        //判断是否存在
        if (null != queryById(entity.getUserName())) {
            //存在则修改
            update(entity);
        } else {
            //不存在则添加
            insert(entity);
        }
    }
}
